package com.zhilian.hzrf_oa.mvp.login.view;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.colin.base.BaseActivity;
import com.colin.utils.LogUtil;
import com.colin.utils.SharedPreferencesUtil;
import com.google.gson.Gson;
import com.zhilian.hzrf_oa.R;
import com.zhilian.hzrf_oa.entity.UserInfo;
import com.zhilian.hzrf_oa.mvp.login.presenter.LoginPresenter;
import com.zhilian.hzrf_oa.mvp.main.view.MainActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by colin on 2018/2/8 9:27 .
 */

public class LoginActivity extends BaseActivity implements ILoginView {


	@BindView(R.id.login_ic_launcher)
	ImageView mLoginIcLauncher;
	@BindView(R.id.login_app_name)
	TextView mLoginAppName;
	@BindView(R.id.loginUser)
	EditText mUserName;
	@BindView(R.id.clear1)
	ImageView mClear1;
	@BindView(R.id.login_box_user)
	LinearLayout mLoginBoxUser;
	@BindView(R.id.loginPassword)
	EditText mPassword;
	@BindView(R.id.clear2)
	ImageView mClear2;
	@BindView(R.id.eye)
	ImageView mEye;
	@BindView(R.id.login_box_password)
	LinearLayout mLoginBoxPassword;
	@BindView(R.id.loginButton)
	Button mLoginButton;
	@BindView(R.id.loginForgetPwd)
	TextView mLoginForgetPwd;
	@BindView(R.id.linearLayout)
	LinearLayout mLinearLayout;
	@BindView(R.id.loginCopyright)
	TextView mLoginCopyright;
	@BindView(R.id.login_support)
	LinearLayout mLoginSupport;
	@BindView(R.id.login_about)
	LinearLayout mLoginAbout;

	private LoginPresenter mPresenter;
	private UserInfo user = new UserInfo();

	@Override
	protected int layoutRes() {
		return R.layout.activity_login;
	}

	@Override
	protected void initViewData() {
		UserInfo user = new SharedPreferencesUtil(this, "hzrf-oa").getObject("user", UserInfo.class);

		mPresenter = new LoginPresenter(this);

		if (null != user) {
			mPresenter.login(user.getUserName(), user.getPassWord());
		}
	}

	@Override
	protected void initView() {

	}

	@Override
	protected void updateView() {

	}




	@Override
	public void login() {
		new SharedPreferencesUtil(this,"hzrf-oa").saveObject("user",new Gson().toJson(user));
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);
		finish();
	}



	@OnClick(R.id.loginButton)
	public void onViewClicked() {
		user.setUserName(mUserName.getText().toString().trim());
		user.setPassWord(mPassword.getText().toString().trim());
		if (null != user){
			mPresenter.login(user.getUserName(),user.getPassWord());
		}
	}
}
